package com.zhongzhi.javafx.controller;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;

import com.zhongzhi.common.co;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.control.Button;

public class CurveController implements Initializable{
	@FXML
	private AreaChart<String, Double> xy;

    @FXML
    private Button aaa;
    
    @FXML
    private CategoryAxis xx;

    @FXML
    private NumberAxis yy;

	
	private HashMap<Long, Double> mapaa = new HashMap<Long, Double>();
	private HashMap<Long, Double> mapbb = new HashMap<Long, Double>();

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		
		yy.setLowerBound(250.0);
		yy.setUpperBound(350);
		
		mapaa = co.getMapaa();
		mapbb = co.getMapbb();
		
		XYChart.Series<String, Double> a = new XYChart.Series<>();
		a.setName("a");
		XYChart.Series<String, Double> b = new XYChart.Series<>();
		b.setName("b");
		Series<String, Double> c = setser(a, mapaa);
		Series<String, Double> d = setser(b, mapbb);
		xy.setHorizontalZeroLineVisible(true);
		xy.getData().addAll(c,d);
	}
	
	private XYChart.Series<String, Double> setser(XYChart.Series<String, Double> a,HashMap<Long, Double> map){
		Set<Long> keySet = map.keySet();
		Long i = 0L;
		for (Long long1 : keySet) {
			Double double1 = map.get(long1);
			a.getData().add(new XYChart.Data(i.toString(), double1));
			i++;
		}
		return a;
	}

}
